import { defineStore } from 'pinia';
import { getW1055046 } from '@/api/etfpegging.js'
const dataSourceMap = {
  'WD': '万得',
  'DZH': '大智慧'
} as const;
export const useLabelStore = defineStore('label', {
  state: () => ({
    defaultLabel: 'wind' as string,
    dataSource: '' as keyof typeof dataSourceMap,
  }),
  actions: {
    toggleLabel(label: string) {
      this.defaultLabel = dataSourceMap[this.dataSource as keyof typeof dataSourceMap];
      this.dataSource = label === '大智慧' ? 'DZH' : 'WD';
    },
    async fetchW1055046Data(searchContent: string) {
      try {
        const params = {
          searchContent: String(searchContent).substring(0, searchContent.indexOf('(')).trim(), // 使用传入的搜索值
          dataSource: this.dataSource
        };
        const response = await getW1055046(params);
        return response.data;
      } catch (error) {
        console.error('获取数据失败:', error);
        throw error;
      }
    }
  },
});
